package com.honey.mybatis.generator;

import org.java.plugin.Plugin;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Field;
import com.honey.compilation.java.InnerClass;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.StaticBlock;
import com.honey.core.compiler.CompilationException;
import com.honey.core.compiler.ContentType;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.generator.java.extension.point.GeneratorJavaClass;

public class MybatisDaoImplementsExtension extends AbstractMybatisExtension  implements  GeneratorJavaClass{

	private AbstractProduceJavaCompilation abstractProduceJavaCompilation;
	
	private AbstractJavaCompilation abstractJavaCompilation = null;
	
	public MybatisDaoImplementsExtension(Plugin belongPlugin) {
		super(belongPlugin);
	}

	@Override
	public AbstractJavaCompilation createNewCompilation(
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		
		try {
			abstractProduceJavaCompilation = MybatisFactory.getAbstractProduceJavaCompilation(MybatisFactory.MybatisClass.DAO_IMPLEMENTS, mybatisPlugin, introspectSchema, introspectSchemaColumn);			
			abstractJavaCompilation = abstractProduceJavaCompilation.produceCompilation();
			
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		
		return abstractJavaCompilation;
	}

	@Override
	public FullyQualifiedJavaType getType() {
		return abstractJavaCompilation.getType();
	}
	
	@Override
	public Field[] importFields() {
		Field[] answer = null;
		try {
			answer = abstractProduceJavaCompilation.produceFields();
			
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		return  answer ;
		//return (new CreateImplementsImportFields(mybatisPlugin)).createImportFields(introspectSchema, introspectSchemaColumn);
	}

	@Override
	public Method[] importMethods() {
		Method[] answer = null;
		try {
			answer = abstractProduceJavaCompilation.produceMethods();
			
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		return  answer ;
		
//		List<Method> answer = new ArrayList<Method>();
//		answer.add((new CreateCountImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.add((new CreateExistsImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateSelectByPrimaryKeyImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateSelectAllImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateSelectByDynamicImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateSelectOneByDynamicImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateDeleteByDynamicImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateDeleteByPrimaryKeyImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateInsertImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateInsertSelectiveImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateSaveImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateUpdateByImplementsInterfaceMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateUpdateByPrimaryKeySelectiveImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateUpdateByDynamicSelectiveImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		answer.addAll((new CreateUpdateByDynamicImplementsMethod(mybatisPlugin)).createMethod(introspectSchema, introspectSchemaColumn));
//		
//		return answer.toArray( new Method [answer.size()] );
	}
	@Override
	public FullyQualifiedJavaType[] importImportClass() {
		FullyQualifiedJavaType[] answer = null;
		try {
			answer = abstractProduceJavaCompilation.produceImportClass();
			
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		return  answer ;
	}

	@Override
	public InnerClass[] importInnerClass() {
		return null;
	}

	@Override
	public InnerEnum[] importInnerEnumClass() {
		return null;
	}

	@Override
	public StaticBlock[] importStaticBlocks() {
		return null;
	}
	
	/* (non-Javadoc)
	 * @see com.honey.generator.java.extension.point.GeneratorJavaClass#getContentType()
	 */
	@Override
	public ContentType getContentType() {
		
		return ContentType.JAVA_DAO_IMPLEMENTS;
	}
}
